<template>
	<view class="priceComparison">
		<view class="public-nav">
			<view class="public-nav-fixed">
				<view class="public-nav-top" style="background-color: #007AFF;color: #FFFFFF;">
					<view class="public-nav-top-status-bar" :style="{ height: systemInfo.statusBarHeight + 'px' }">
					</view>
					<view class="public-nav-top-navbar-inner" :style="{ height: navHeight + 'px', lineHeight: navHeight + 'px' }">
						<text class="iconfont iconarrow_left-copy" @click="returnclick"></text>
						<view>物料价格比对</view>
					</view>
				</view>
			</view>
			<view class="public-nav-placeholder"
				:style="{ height: Number(navHeight) + Number(systemInfo.statusBarHeight) + 'px' }">
			</view>
		</view>
		<view class="priceComparison-table">
			<view class="priceComparison-table-btn">
				<view type="default" :class="item.SETTB206CA00 == materinfo.SETTB206CA00 ? 'priceComparison-table-btn-active' : ''"
					v-for="(item, index) in MaterList" :key='item.SETTB206CA00' @click="materClick(item)">
					{{ item.SETTB206CA01 }}</view>
			</view>
			<view class="priceComparison-ul">
				<view class="priceComparison-ul-title">
					{{ materinfo.SETTB206CA01 || '' }}
				</view>
				<view class="priceComparison-ul-li" v-for="(item, index) in ErpMaterList" :key='index' @click="itmeclick(item)">
					<view class="priceComparison-ul-li-img">
						<image :src="item.SETTB109CA07 || getStaticFilePath('/home/zw/no-meater.png')" mode=""></image>
					</view>
					<view class="priceComparison-ul-li-text">
						<view class="priceComparison-ul-li-text-q">
							{{ item.SETTB99CA00 || '' }}
						</view>
						<view class="priceComparison-ul-li-text-w">
							{{ item.SETTB206CA01 || '' }}
						</view>
						<view class="priceComparison-ul-li-text-">
							<text v-if="AuthorizationOBJ.ORMTB417CA06 == 0"> ￥*** </text>
							<view class="" v-else>
								<text>￥{{ item.SETTB109CA01_ys || '' }}</text>/{{ item.SETTB109CA05 || '吨' }}<text
									style="color: #333;font-size: 18rpx;">（优惠{{ item.SETTB109CA01 || 0 }}）</text>
							</view>
						</view>
					</view>
				</view>
				<view class="" style="height: 200rpx;"></view>
				<view class="sendorder-loadmore">
					<u-loadmore v-if="MaterList.length != 0" :status="status" :icon-type="iconType" :load-text="loadText" />
				</view>
				<view class="public-no-img" style="margin-left: 100rpx;" v-if="MaterList.length > 0 && ErpMaterList.length == 0">
					<image :src="getStaticFilePath('/QXY/noData.png')"></image>
				</view>
			</view>
		</view>
		<view class="public-no-img" v-if="MaterList.length == 0">
			<image :src="getStaticFilePath('/QXY/noData.png')"></image>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			background: {
				backgroundColor: '#00a1f1',
			},
			userinfo: JSON.parse(uni.getStorageSync('userinfo')),
			city: uni.getStorageSync('city') ? JSON.parse(uni.getStorageSync('city')) : {},
			AuthorizationOBJ: '',
			MaterList: [],
			materinfo: '',
			ErpMaterList: [],
			page: 1,
			countpage: 1,
			systemInfo: '',
			navHeight: '',
			status: 'loading',
			iconType: 'flower',
			loadText: {
				loadmore: '轻轻上拉',
				loading: '努力加载中',
				nomore: '实在没有了'
			},

		}
	},
	onShow: function () {

		uni.removeStorageSync('erpinfo')
		uni.removeStorageSync('materInfo')
		uni.removeStorageSync('Erptype')
		this.systemInfo = uni.getSystemInfoSync()
		this.navHeight = this.systemInfo.platform == 'ios' ? 44 : 48;
		this.queryMaterList()
		if (this.userinfo.sign == 'CUS-3') {
			this.queryAuthorization()
		}
	},
	onReachBottom() {
		if (this.page == this.countpage) {
			return this.status = "nomore"
		}
		this.page++
		this.queryList()
	},

	methods: {
		returnclick() {
			uni.navigateBack({ delta: 1 })
		},
		itmeclick(item) {
			if (this.AuthorizationOBJ.ORMTB417CA05 && this.AuthorizationOBJ.ORMTB417CA05 == 0) {
				uni.showToast({
					title: '您没有操作权限',
					duration: 5000,
					icon: 'none',
				});
				return
			}
			var erp = {
				"SETTB100ID": item.SETTB100ID || '',
				"SETTB99CA00": item.SETTB99CA00 || '',
				"SETTB99CA01": item.SETTB109CA01 || '',
				"ORMTB401CA01": item.ORMTB401CA01 || '',
				"SETTB99CA02": item.SETTB99CA02 || '',
				"SETTB99ID": item.SETTB99ID || ''
			}
			var mater = {
				"settb109ID": item.SETTB109ID || '',
				"settb99ID": item.SETTB99ID || '',
				"settb109CA00": item.SETTB109CA00 || '',
				"settb109CA01": item.SETTB109CA01 || '',
				"settb109CA02": item.SETTB109CA02 || '',
				"settb109CA03": item.SETTB109CA03 || '',
				"settb109CA04": item.SETTB109CA04 || '',
				"settb109CA05": item.SETTB109CA05 || '',
				"settb109CA06": item.SETTB109CA06 || '',
				"settb109CA07": item.SETTB109CA07 || '',
				"settb109CD01": item.SETTB100ID || '',
			}
			erp = JSON.stringify(erp)
			mater = JSON.stringify(mater)
			uni.setStorageSync('materInfo', mater);
			uni.setStorageSync('erpinfo', erp);
			uni.setStorageSync('Erptype', 3);
			uni.navigateTo({
				url: '/pages/SOcar/index'
			})
		},
		materClick(item) {
			this.materinfo = item
			this.page = 1
			this.countpage = 1
			this.ErpMaterList = []
			this.queryList()
		},
		queryMaterList() {
			this.MaterList = []
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			uni.request({
				url: this.baseUrl + '/set/settb109/selectMAT',
				method: 'GET',
				success: (res) => {
					uni.hideLoading();
					if (res.data.code == 200) {
						this.MaterList = res.data.data || []
						this.materinfo = this.MaterList[0]
						this.queryList()
					} else {
						this.$refs.uToast.show({
							title: res.data.success,
							type: 'default',
							icon: false
						})
					}
				},
				fail: (res) => {
					uni.hideLoading();
					this.$refs.uToast.show({
						title: res.errMsg,
						type: 'default',
						icon: false
					})
				}
			});
		},
		queryList() {
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			this.status = "loading"
			var ORMTB410ID = ''
			if (this.userinfo.sign == "CUS-2" || this.userinfo.sign == 'CUS-3') {
				ORMTB410ID = this.userinfo.ORMTB410ID
			}
			uni.request({
				url: this.baseUrl + '/set/settb109/selectSETTB109CB00',
				method: 'POST',
				dataType: 'json',
				data: {
					page: this.page,
					limit: 10,
					SETTB100CA04: this.city.CODETB01CA00, //市代码
					SETTB206CA00: this.materinfo.SETTB206CA00, //物料类别代码值
					ORMTB410ID: ORMTB410ID,
					sign: this.userinfo.sign,
				},
				success: (res) => {
					console.log(res);
					uni.hideLoading();
					if (res.data.code == 200) {
						if (!res.data.data || res.data.data == null) {
							this.ErpMaterList = []
							this.page = 1
							this.countpage = 1
							return
						}
						var data = res.data.data || []
						if (this.page > 1) {
							this.ErpMaterList = [...this.ErpMaterList, ...data]
							console.log(this.ErpMaterList)
						} else {
							this.ErpMaterList = data
						}
						this.countpage = Math.ceil(res.data.count / 10)
					} else {
						this.ErpMaterList = []
						this.page = 1
						this.countpage = 1
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'default',
							icon: false
						})
					}
					if (this.countpage == this.page) {
						this.status = "nomore"
					} else {
						this.status = "loadmore"
					}
				},
				fail: (res) => {
					if (this.countpage == this.page) {
						this.status = "nomore"
					} else {
						this.status = "loadmore"
					}
					uni.hideLoading();
					this.$refs.uToast.show({
						title: res.errMsg,
						type: 'default',
						icon: false
					})
				}
			});
		},
		queryAuthorization() { //查询子账户权限
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			uni.request({
				url: this.baseUrl + '/orm/ormtb417/selectAccess/' + this.userinfo.ORMTB417ID,
				method: 'GET',
				success: (res) => {
					console.log(res);
					uni.hideLoading();
					if (res.data.code == 200) {
						this.AuthorizationOBJ = res.data.data
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'default',
							icon: false
						})
					}
				},
				fail: (res) => {
					uni.hideLoading();
					this.$refs.uToast.show({
						title: res.errMsg,
						type: 'default',
						icon: false
					})
				}
			});
		},
	}
}
</script>

<style scoped>
.priceComparison-title {
	display: flex;
	padding: 20rpx 0 20rpx 40rpx;
}

.priceComparison-title text {
	line-height: 55rpx;
}

.priceComparison-title-click view {
	width: 40rpx;
	text-align: center;
}

.priceComparison-title-click .iconshangjiantou {
	font-size: 30rpx;
}

.priceComparison-title-click .iconxiala {
	font-size: 15rpx;
}

.priceComparison-table {
	display: flex;
	margin-top: 10rpx;
}

.priceComparison-table-btn {
	position: fixed;
	height: 100%;
	width: 160rpx;
	z-index: 999;
	background-color: #FFF;
	left: 0;
}

.priceComparison-table-btn>view {
	width: 160rpx;
	height: 80rpx;
	line-height: 80rpx;
	color: #333;
	background-color: #E5E5E5;
	/* font-size: 30rpx; */
	border-radius: 0;
	padding: 0 10rpx;
	border-bottom: 1px solid #fff;
	text-align: center;
}

.priceComparison-table-btn .priceComparison-table-btn-active {
	background-color: #FFF;
}

.priceComparison-ul {
	position: relative;
	left: 180rpx;
	padding: 0 10rpx;
	padding-top: 80rpx;

}

.priceComparison-ul-li-img>image {
	width: 150rpx;
	height: 120rpx;
}

.priceComparison-ul-li {
	display: flex;
}

.priceComparison-ul-li-text {
	padding: 0 0 0 20rpx;
	font-size: 32rpx;
}

.priceComparison-ul-li-text text {
	color: red;
	font-style: oblique;
	margin-right: 10rpx;
}

.priceComparison-ul-li-text-q {}

.priceComparison-ul-li-text-w {
	margin-top: 5rpx;
	font-size: 30rpx;
}

.priceComparison-ul-li-text-p {
	margin-top: 5rpx;
}

.priceComparison-ul-title {
	position: fixed;
	top: 88rpx;
	z-index: 999;
	width: 100%;
	background: #fff;
	/* font-size: 30rpx; */
	color: #333;
	margin-bottom: 20rpx;
	font-weight: 500;
}
</style>
